package com.ys.erp.stage_marketing_service.controller;

import com.ys.erp.framework.annotation.CheckEmpLogin;
import com.ys.erp.framework.annotation.ResponseResult;
import com.ys.erp.framework.annotation.StageLoginEmp;
import com.ys.erp.framework.bean.dto.StageEmpDTO;
import com.ys.erp.framework.response.PageDTO;
import com.ys.erp.stage_marketing_service.bean.condition.CouponsCondition;
import com.ys.erp.stage_marketing_service.bean.vo.CouponSendRecordVO;
import com.ys.erp.stage_marketing_service.bean.vo.CouponStatisticsVO;
import com.ys.erp.stage_marketing_service.bean.vo.CouponVO;
import com.ys.erp.stage_marketing_service.service.CouponsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author lwj
 * @date 2023/5/31
 */
@ResponseResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/marketing/preferential")
@Tag(name = "CouponsController", description = "营销中心优惠卷相关接口")
public class CouponsController {

    private final CouponsService cardCouponService;


    @PostMapping("/pageCoupon")
    @CheckEmpLogin
    @Operation(summary = "分页优惠券列表", description = "分页优惠券列表")
    public PageDTO<CouponVO> pageCoupon(@RequestBody @Valid CouponsCondition.PageCouponCon con,
                                        @StageLoginEmp StageEmpDTO emp) {
        return cardCouponService.pageCoupon(emp, con);
    }

    @PostMapping("/addOrUpdateCoupon")
    @CheckEmpLogin
    @Operation(summary = "添加或更新优惠券", description = "添加或更新优惠券")
    @Deprecated
    public void addOrUpdateCoupon(@RequestBody @Valid CouponsCondition.AddOrUpdateCouponCon con,
                                  @StageLoginEmp StageEmpDTO emp) {

        cardCouponService.addOrUpdateCoupon(emp, con);
    }

    @GetMapping("/getCouponDetail")
    @CheckEmpLogin
    @Operation(summary = "获取优惠券详情", description = "获取优惠券详情")
    public CouponVO getCouponDetail(@RequestParam("couponId") Long couponId,
                                    @StageLoginEmp StageEmpDTO emp) {

        return cardCouponService.getCouponDetail(couponId);
    }

    @PostMapping("/grantCoupon")
    @CheckEmpLogin
    @Operation(summary = "发放优惠券", description = "发放优惠券")
    public void grantCoupon(@RequestBody @Valid CouponsCondition.GrantCouponCon con,
                            @StageLoginEmp StageEmpDTO emp) {
        cardCouponService.grantCoupon(emp, con);
    }

    @PostMapping("/couponStatistics")
    @CheckEmpLogin
    @Operation(summary = "优惠券统计", description = "优惠券统计")
    public CouponStatisticsVO couponStatistics(@RequestBody @Valid CouponsCondition.CouponStatisticsCon con,
                                               @StageLoginEmp StageEmpDTO emp) {
        return cardCouponService.couponStatistics(con);
    }

    @PostMapping("/pageCouponSendRecord")
    @CheckEmpLogin
    @Operation(summary = "分页优惠券发放记录", description = "分页优惠券发放记录")
    public PageDTO<CouponSendRecordVO> pageCouponSendRecord(@RequestBody @Valid CouponsCondition.PageCouponSentRecordCon con,
                                                            @StageLoginEmp StageEmpDTO emp) {
        return cardCouponService.pageCouponSendRecord(con);
    }

}
